/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 通知玩家进入关卡的数据
	/// module : levelLogic
	/// </summary>
	public class EnterLevelPOD : IPOD 
    {
        public readonly static Func<EnterLevelPOD> FACTORY = () => new EnterLevelPOD();
		public static Func<EnterLevelPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        ///  唯一id
        /// </summary>
		public long id;
		/// <summary>
        ///  校验
        /// </summary>
		public int cid;
		/// <summary>
        /// 
        /// </summary>
		public LevelPlayerPOD player;
		/// <summary>
        /// 
        /// </summary>
        private List<LevelOtherPlayerPOD> m_otherPlayers;
		/// <summary>
        /// 
        /// </summary>
		public LevelRegionPOD region;
		/// <summary>
        /// 
        /// </summary>
        private Dictionary<int, int> m_levelParams;
		/// <summary>
        /// 
        /// </summary>
		public int timeHour;
		
		
        public List<LevelOtherPlayerPOD> otherPlayers
        {
            get
            {
                if(m_otherPlayers == null)
                {
                    m_otherPlayers = new();
                }
                return m_otherPlayers;
            }
            private set => m_otherPlayers = value;
        }
        public List<LevelOtherPlayerPOD> unsafe_otherPlayers
        {
        	get => m_otherPlayers;
        	set => m_otherPlayers = value;
        }
        public Dictionary<int, int> levelParams
        {
            get
            {
                if(m_levelParams == null)
                {
                    m_levelParams = new();
                }
                return m_levelParams;
            }
            private set => m_levelParams = value;
        }
        public Dictionary<int, int> unsafe_levelParams
        {
        	get => m_levelParams;
        	set => m_levelParams = value;
        }
		
		/*-- constructors --*/
		public EnterLevelPOD() {}
		public EnterLevelPOD(long id, int cid, LevelPlayerPOD player, List<LevelOtherPlayerPOD> otherPlayers, LevelRegionPOD region, Dictionary<int, int> levelParams, int timeHour) {
			this.id = id;
			this.cid = cid;
			this.player = player;
			this.m_otherPlayers = otherPlayers;
			this.region = region;
			this.m_levelParams = levelParams;
			this.timeHour = timeHour;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_long(id);
            _out.Write_int(cid);
            _out.Write_pod(player);
            _out.Write_list_pod(m_otherPlayers);
            _out.Write_pod(region);
            _out.Write_map_int_int(m_levelParams);
            _out.Write_int(timeHour);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            id = _in.Read_long();
            if(!_in.HasRemaining()) return;
            cid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            player = _in.Read_pod<LevelPlayerPOD>(LevelPlayerPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            m_otherPlayers = _in.Read_list_pod<LevelOtherPlayerPOD>(LevelOtherPlayerPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            region = _in.Read_pod<LevelRegionPOD>(LevelRegionPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            m_levelParams = _in.Read_map_int_int();
            if(!_in.HasRemaining()) return;
            timeHour = _in.Read_int();
        }
		
		public EnterLevelPOD Clone() {
            EnterLevelPOD o = DynamicFactory();
            o.id = id;
            o.cid = cid;
            if (player != null) {
                o.player = player.Clone();
            }
            if (m_otherPlayers != null) {
                o.m_otherPlayers = m_otherPlayers.ConvertAll(o => o?.Clone());
            }
            if (region != null) {
                o.region = region.Clone();
            }
            if (m_levelParams != null) {
                o.m_levelParams = new (m_levelParams);
            }
            o.timeHour = timeHour;
            return o;
        }
        
        public void Clear() {
            id = default;
            cid = default;
            player = default;
            m_otherPlayers = default;
            region = default;
            m_levelParams = default;
            timeHour = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "EnterLevelPOD [";
			str += "id=";
			str += id;
			str += ", cid=";
			str += cid;
			str += ", player=";
			str += player;
			str += ", otherPlayers=";
			str += m_otherPlayers.ToString<LevelOtherPlayerPOD>();
			str += ", region=";
			str += region;
			str += ", levelParams=";
			str += m_levelParams.ToString<int, int>();
			str += ", timeHour=";
			str += timeHour;
			str += "]";
			return str;
		}
		
	}
}